﻿
using System.Web;
using System.Web.Hosting;
using System.Web.Mvc;
using Dexter.Dependency;
using Dexter.Dependency.Installation;
using Dexter.Web.Mvc.Controllers;
using Dexter.Web.Mvc.Filters;
using Dexter.Web.Mvc.ResourceCombiner;
using Dexter.Web.Mvc.Routing;
using Dexter.Web.Mvc.ViewEngines;
using Dexter.Web.Routing;
using Elmah;
using RazorViewEngine = Dexter.Web.Mvc.ViewEngines.RazorViewEngine;
using WebFormViewEngine = Dexter.Web.Mvc.ViewEngines.WebFormViewEngine;

namespace Dexter.Web.Mvc.Installer {
	public class ServiceInstaller : ILayerInstaller{
		/// <summary>
		/// 	Installs all the component needed by the assembly.
		/// </summary>
		/// <param name = "container">The container.</param>
		public void ServiceRegistration ( IDexterContainerRegister container ) {
			container.Register <IDexterApplication , DexterApplication> ( "DexterApplication" , LifeCycle.Singleton );
			container.Register<ICombiner, Combiner> ( "Combiner", LifeCycle.Singleton );
			container.Register<IControllerFactory, DexterControllerFactory> ( "DexterControllerFactory", LifeCycle.Singleton );
			container.Register<IViewEngine, WebFormViewEngine> ( "WebFormViewEngine", LifeCycle.Singleton );
			container.Register<IViewEngine, RazorViewEngine> ( "RazorViewEngine", LifeCycle.Singleton );
			container.Register<IViewEngine, SparkViewEngine> ( "SparkViewEngine", LifeCycle.Singleton );
			container.Register<IRoutingService, RoutingService> ( "RoutingService", LifeCycle.Singleton );
			container.Register<IHttpModule, ErrorLogModule> ( "ErrorLogModule", LifeCycle.Singleton );
			//container.Register<FilterAttribute, CompressionFilter> ( "CompressionFilter", LifeCycle.Singleton );
			//container.Register<FilterAttribute, StripWhiteSpaceFilter> ( "StripWhiteSpaceFilter", LifeCycle.Singleton );
			container.Register<FilterAttribute, DexterCallFilter> ( "DexterCallFilter", LifeCycle.Singleton );
			container.Register<VirtualPathProvider, DexterVirtualPathProvider> ( "VirtualPathProvider", LifeCycle.Singleton );
			container.RegisterComponentsByBaseClass<Controller> ( this.GetType ( ).Assembly, LifeCycle.Transient );
		}

		/// <summary>
		/// 	Setups the service.
		/// </summary>
		/// <param name = "container">The container.</param>
		public void ServiceRegistrationComplete ( IDexterContainerResolver container ) {
			( ( SparkViewEngine )container.Resolve<IViewEngine> ( "SparkViewEngine" ) ).AutoRegisterThemes ( );
		}

		/// <summary>
		/// 	Setups the service.
		/// </summary>
		/// <param name = "container">The container.</param>
		public void ApplicationStarted ( IDexterContainerResolver container ) {
			
		}
	}
}
